import http from './http'

// 获取商家订单列表
export function getSellerOrders(params) {
  // params: { pageNum, pageSize, sellerId, status?, keyword?, itemStatus? }
  return http.get('/orders/getSellerOrder', { params })
}

// 获取订单详情
export const getOrderDetail = (orderId) => {
  return http.get('/orders/queryOrderMessage', {
    params: { orderId }
  })
}

// 商家发货
export function shipOrder(payload) {
  // payload: { orderId, ItemId }
  return http.put('/orders/deliverOrder', null, {
    params: {
      orderId: payload.orderId,
      ItemId: payload.ItemId
    }
  })
}

// 更新订单状态
export function updateOrderStatus(payload) {
  // payload: { orderId, status }
  return http.put('/orders/status', payload)
}

// 更新订单状态（取消订单、完成订单等）
export function updateOrderStatusApi(orderId, status) {
  return http.put('/orders/updateOrderStatus', null, {
    params: {
      orderId: orderId,
      status: status
    }
  })
}

// 取消订单
export function cancelOrder(orderId) {
  return updateOrderStatusApi(orderId, 5)
}

// 完成订单
export function completeOrder(orderId) {
  return updateOrderStatusApi(orderId, 4)
}

// 更新订单项状态
export function updateOrderItemStatus(payload) {
  // payload: { orderItemId, itemStatus }
  return http.put('/orders/item-status', payload)
}

// 获取客户订单列表
export function getCustomerOrders(params) {
  // params: { pageNum, pageSize, customerId, status? }
  return http.get('/orders/getCustomerOrder', { params })
}

// 创建订单
export function createOrder(payload) {
  // payload: OrderCreateDTO
  return http.post('/orders/addOrder', payload)
}

// 获取订单号
export function getOrderNumber(customerId) {
  return http.get('/orders/getOrderNumber', {
    params: { customerId }
  })
}

// 查询日销售数据
export function queryDailySales(sellerId, year, month) {
  return http.get('/orders/queryDailySales', {
    params: { sellerId, year, month }
  })
}

// 查询月销售数据
export function queryMonthlySales(sellerId, year) {
  return http.get('/orders/queryMonthlySales', {
    params: { sellerId, year }
  })
}

// 确认收货
export function confirmOrder(orderId) {
  return http.put(`/orders/${orderId}/confirm`)
}

// 申请退款
export function requestRefund(payload) {
  // payload: { orderId, reason, amount? }
  return http.post('/orders/refund', payload)
}

// 处理退款申请
export function handleRefund(payload) {
  // payload: { refundId, status, remark? }
  return http.put('/orders/refund/handle', payload)
}